//
//  WelcomeView.m
//  DreamSoftReimburse
//
//  Created by ZJ on 17/4/13.
//  Copyright © 2017年 ZJ. All rights reserved.
//

#import "WelcomeView.h"
#import "ZJAdditions.h"
@interface WelcomeView ()<UIScrollViewDelegate>
/** uiscollView */
@property (nonatomic, strong) UIScrollView *scrollView;
@end

@implementation WelcomeView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self addSubview:self.scrollView];
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    //初始化欢迎页面
    NSArray *array = @[@"welcomepage",@"welcomepage",@"welcomepage",@"welcomepage"];
    for (int i = 0; i < array.count; i ++) {
        UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.width,0 , self.width  , self.height)];
        imageview.image = [UIImage imageNamed:array[i]];
        [self.scrollView addSubview:imageview];
    }
    self.scrollView.contentSize = CGSizeMake(self.width * array.count, self.scrollView.height);
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(self.width * (array.count - 1), 0, self.width , self.height )];
    [button addTarget:self action:@selector(action_button) forControlEvents:UIControlEventTouchUpInside];
    
    [self.scrollView addSubview:button];

}

#pragma mark - 按钮被点击
- (void)action_button{
    NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
    NSString *currentVersion = [infoDict objectForKey:@"CFBundleShortVersionString"];
    [[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:@"currentversion"];
    if (self.delegate && [self.delegate respondsToSelector:@selector(didClickEnterNext)]) {
        [self.delegate didClickEnterNext];
    }
}



#pragma mark - Setter


#pragma mark - Getters
- (UIScrollView *)scrollView{

    if (_scrollView == nil){
        _scrollView = [[UIScrollView alloc]initWithFrame:self.bounds];
        _scrollView.contentSize = CGSizeMake(self.width * 3, self.height);
        _scrollView.contentOffset = CGPointMake(0, 0);
        _scrollView.showsVerticalScrollIndicator = NO;
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.pagingEnabled = YES;
        _scrollView.delegate = self;
        //回弹
        _scrollView.bounces = NO;
        _scrollView.backgroundColor = [UIColor whiteColor];
    }
    return _scrollView;
}


@end
